/**
 *	 defined the main entry program
 *   VisualGroup JavaScript prototype Classes, version draf
 *  (c) 2008 Bill Vison <vison_ruan@126.com>
 *
 *
/*--------------------------------------------------------------------------*/
LoaderClassesCache = Ext.extend(Ext.util.Observable , {
	
	_tmpLoadClasses:[],
	
	_loadClasses:new Ext.util.MixedCollection(),

	/** 
	 *	@param {object} initialze the main object manager
	 *	@constructor 
	 */
	constructor:function($config) {
		
		LoaderClassesCache.superclass.constructor.apply(this, arguments);
		
	},

	
	/**
	 * Retrieves and removes the head of this queue, or returns null if this array is empty.
	 */
	poll:function() {
		return this._tmpLoadClasses.shift();
	},
	
	
	/**
	 * the temporary class array
	 */
	getTemporaryLoadClass : function() {
		return this._tmpLoadClasses;
	},
	
	/**
	 * add a class to the loader classes manager.
	 * @param className defined the class string
	 */
	addClass:function($className) {

		if (!this.contain($className)) {
		
			// --- put the class to array ---
			this._tmpLoadClasses.push( $className );

			// --- add the state , and init the value --- 
			var $loadClassState = {
				state:LoadClassState.INITIALIZE
			}
			this._loadClasses.add($className , $loadClassState);
		}
		
	},
	
	getLoadClasses : function() {
		return this._loadClasses;
	},
	
	
	/**
	 * load all pre loades classes 
	 */
	getAllPreLoadClasses:function() {
		var $preLoadClasses = [];
		this._loadClasses.eachKey(function($key) {
			$preLoadClasses.push( $key );
		});
		return $preLoadClasses;
	},
	
	/**
	 * return the class state
	 */
	get:function($key) {
		return this._loadClasses.get( $key );
	},
	
	set:function($key , $stateobj) {
		return this._loadClasses.replace( $key , $stateobj );
	},
	
	/**
	 * 	check the class need to load if in container
	 *	return the object if contain
	 */
	contain:function($className)  {
		
		
		if ($className == null || $className == "") {
			throw new LoaderClassesCache.Exception("类名不能为空! ", null , Exception.NullObjectException);
		}

		return this._loadClasses.containsKey($className);
	}
	 
	
});

/**
 * defined some exception for the loader classes manager
 */
LoaderClassesCache.Exception = Ext.extend(Exception,{
	name:"LoaderClassesCache.Exception",
	constructor:function($message , $name ,$value) {
		LoaderClassesCache.Exception.superclass.constructor.apply(this, arguments);
	}
});

